<?php
/**
 * Created by PhpStorm.
 * User: august
 * Date: 2021/5/19
 * Time: 18:24
 */

namespace DesignPatterns\Structure\Flyweight;

/**
 * 享元工厂
 * Class FlyweightFactory
 * @package DesignPatterns\Structure\Flyweight
 */
class FlyweightFactory
{
    private $flyweights = [];

    public function getFlyweight($name):Flyweight
    {
        if (!isset($this->flyweights[$name])) {
            $this->flyweights[$name] = new ConcreteFlyweight($name);
        }

        return $this->flyweights[$name];
    }
}